/*--------------------------------------------------------------------------------
 * Adaptive Intelligence - Foundation Framework Class Library
 * Version 2.00
 * 
 * Service Dependents Event Arguments Class
 *		Provides an event arguments implementation for service dependents events.
 *------------------------------------------------------------------------------*/

/*--------------------------------------------------------------------------------
 * System Imports
 *------------------------------------------------------------------------------*/
using System;
using System.ServiceProcess;
using Adaptive.Foundation.SysTools;

namespace Adaptive.Foundation
{
    /// <summary>
    /// Provides an event arguments implementation for service dependents events.
    /// </summary>
    /// <remarks>
    /// This is used to notify the caller when action on a service may cause a cascading
    /// operation on other services.
    /// </remarks>
    public sealed class DependentEventArgs : System.EventArgs, IDisposable
    {
        /*--------------------------------------------------------------------------------
         * Private Member Declarations
         *------------------------------------------------------------------------------*/
        #region Private Member Declarations
        /// <summary>
        /// Contains the list of dependent service references.
        /// </summary>
        private ServiceControllerExCollection _listOfDepedents;
        /// <summary>
        /// Continue or cancel flag.
        /// </summary>
        private bool _continue;
        #endregion

        /*--------------------------------------------------------------------------------
         * Constructor / Dispose / Destructor Methods
         *------------------------------------------------------------------------------*/
        #region Constructor / Dispose / Destructor Methods
        /// <summary>
        /// Initializes a new instance of the class.
        /// </summary>
        /// <value>
        /// This is the default constructor.
        /// </value>
        public DependentEventArgs()
        {
            _listOfDepedents = new ServiceControllerExCollection();
        }
        /// <summary>
        /// Initializes a new instance of the class.
        /// </summary>
        /// <param name="serviceController">
        /// A <see cref="ServiceController"/> indicating the dependent service.
        /// </param>
        public DependentEventArgs(ServiceController serviceController)
        {
            _listOfDepedents = new ServiceControllerExCollection();
            _listOfDepedents.Add(new ServiceControllerEx(serviceController.ServiceName));
        }
        /// <summary>
        /// Initializes a new instance of the class.
        /// </summary>
        /// <param name="servicesList">
        /// A <see cref="ServiceController"/> array containing the depdendent services.
        /// </param>
        public DependentEventArgs(ServiceController[] servicesList)
        {
            _listOfDepedents = new ServiceControllerExCollection();
            foreach (ServiceController serviceController in servicesList)
                _listOfDepedents.Add(new ServiceControllerEx(serviceController.ServiceName));
        }
        /// <summary>
        /// Initializes a new instance of the class.
        /// </summary>
        /// <param name="servicesList">
        /// A <see cref="ServiceControllerExCollection"/> instance containing the depdendent services.
        /// </param>
        public DependentEventArgs(ServiceControllerExCollection servicesList)
        {
            _listOfDepedents = servicesList;
        }
        /// <summary>
        /// Deallocates internally allocated objects.
        /// </summary>
        public void Dispose()
        {
            if (_listOfDepedents != null)
                _listOfDepedents.Dispose();

            _listOfDepedents = null;
            GC.SuppressFinalize(this);
        }
        /// <summary>
        /// Class destructor.
        /// </summary>
        ~DependentEventArgs()
        {
            Dispose();
        }
        #endregion

        /*--------------------------------------------------------------------------------
         * Public Properties
         *------------------------------------------------------------------------------*/
        #region Public Properties
        /// <summary>
        /// Gets the reference to the list of depdendent services.
        /// </summary>
        /// <value>
        /// A <see cref="ServiceControllerExCollection"/> instance.
        /// </value>
        public ServiceControllerExCollection DependentServices
        {
            get { return _listOfDepedents; }
        }
        /// <summary>
        /// Gets or sets a value indicating whether the originating operation
        /// should continue or be cancelled.
        /// </summary>
        /// <value>
        /// <b>true</b> to continue the originating operation; otherwise,
        /// <b>false</b> to cancel.
        /// </value>
        public bool ContinueOperation
        {
            get { return _continue; }
            set { _continue = value; }
        }
        #endregion
    }
}